package service.impl;

import dao.mapper.AdminMapper;
import dao.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import service.AdminService;
import service.UserService;

import java.io.IOException;
import java.io.InputStream;

public class AdminServiceImpl implements AdminService {
    UserService userService;
    @Override
    public void banUser(Integer userId) {
        userService.banUser(userId);
    }
    @Override
    public void unbanUser(Integer userId) {
        userService.unbanUser(userId);
    }

    @Override
    public void deleteUser(Integer userId) {
        userService.deleteUser(userId);
    }

    @Override
    public void reviewAppeal(String userId) {

    }

    @Override
    public void reviewReport(String reportId) {

    }

    @Override
    public boolean isadmin(String adminname){
       /* InputStream is = null;
        try{
            is=Resources.getResourceAsStream("mybatis-config.xml");
        }catch(IOException e){
            throw new RuntimeException(e);
        }
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder;
        SqlSessionFactory sq =sqlSessionFactoryBuilder.build(is);
        SqlSession sqlSession=sqlSessionFactory.openSession(b:true);
        AdminMapper adminMapper=sqlSession.getMapper(AdminMapper.class);
*/
        InputStream is= null;
        try {
            is = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory=sqlSessionFactoryBuilder.build(is);
        SqlSession sqlSession=sqlSessionFactory.openSession(true);
        AdminMapper adminMapper=sqlSession.getMapper(AdminMapper.class);
        if(adminname==adminMapper.GetAdminName())
            return true;
        else
            return false;
    }
}
